<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/page/common/commonPage.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加模板</title>
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/smartadmin-production.min.css">
</head>
<body>
    <%@ include file="/WEB-INF/page/common/header.jsp"%>
    <%@ include file="/WEB-INF/page/common/leftSideBar.jsp"%>

    <div id="main" role="main">
        <div id="ribbon">
            <ol class="breadcrumb">
                <li>首页</li>
                <li>自定义模板管理</li>
                <li>添加模板</li>
            </ol>
        </div>
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="jarviswidget">
                        <header>
                            <h2><i class="fa fa-plus"></i> 添加模板</h2>
                        </header>
                        <div class="widget-body">
                            <form id="addForm" class="smart-form">
                                <fieldset>
                                    <section>
                                        <label class="label">模板文件</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-file"></i>
                                            <input type="text" name="tplFile" class="form-control">
                                        </label>
                                    </section>
                                    <section>
                                        <label class="label">模板名称</label>
                                        <label class="input">
                                            <i class="icon-append fa fa-pencil"></i>
                                            <input type="text" name="tplName" class="form-control">
                                        </label>
                                    </section>
                                    <section>
                                        <label class="label">模板类型</label>
                                        <label class="select">
                                            <select name="tplType" class="form-control">
                                                <option value="">请选择模板类型</option>
                                                <option value="page">page</option>
                                                <option value="list">list</option>
                                            </select>
                                            <i></i>
                                        </label>
                                    </section>
                                    <section>
                                        <label class="label">模板说明</label>
                                        <label class="textarea">
                                            <i class="icon-append fa fa-pencil"></i>
                                            <textarea name="tplDesc" rows="3" class="form-control"></textarea>
                                        </label>
                                    </section>
                                    <section>
                                        <label class="label">模板内容</label>
                                        <label class="textarea">
                                            <i class="icon-append fa fa-pencil"></i>
                                            <textarea name="content" rows="10" class="form-control"></textarea>
                                        </label>
                                    </section>
                                </fieldset>
                                <footer>
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fa fa-save"></i> 保存
                                    </button>
                                    <button type="button" class="btn btn-default" onclick="window.location.href='${base}/template/custom'">
                                        <i class="fa fa-reply"></i> 返回
                                    </button>
                                </footer>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${resourcesUrl}/common/js/jquery-1.8.2.min.js"></script>
    <script src="${resourcesUrl}/common/js/bootstrap/bootstrap.min.js"></script>
    <script src="${resourcesUrl}/common/js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script src="${resourcesUrl}/common/components/artDialog/dialog-min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#addForm").validate({
                rules: {
                    tplFile: {
                        required: true
                    },
                    tplName: {
                        required: true
                    },
                    tplType: {
                        required: true
                    }
                },
                messages: {
                    tplFile: {
                        required: "请输入模板文件"
                    },
                    tplName: {
                        required: "请输入模板名称"
                    },
                    tplType: {
                        required: "请输入模板类型"
                    }
                },
                submitHandler: function(form) {
                    var formData = $(form).serialize();
                    $.ajax({
                        type: "POST",
                        url: "${base}/template/create",
                        data: formData,
                        success: function(data) {
                            if (data.RET_CODE === "success") {
                                dialog({
                                    title: '提示',
                                    content: '添加成功',
                                    ok: function() {
                                        window.location.href = '${base}/template/custom';
                                    }
                                }).showModal();
                            } else {
                                dialog({
                                    title: '错误',
                                    content: data.RET_OBJ || '添加失败'
                                }).showModal();
                            }
                        }
                    });
                    return false;
                }
            });
        });
    </script>
    <%@ include file="/WEB-INF/page/common/footer.jsp"%>
</body>
</html> 